package com.sanley.piss.model.exceptionUtil.exception;

import com.sanley.piss.model.exceptionUtil.json.ResultEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * Create By  on 2021/3/5.
 */
@Data
@NoArgsConstructor
public class ResultEntity {
    /**
     * 相应代码
     */
    private String code;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 响应结果
     */
    private Object data;

    public ResultEntity(BaseErrorInfoInterface baseErrorInfoInterface) {
        this.code=baseErrorInfoInterface.getResultCode();
        this.message=baseErrorInfoInterface.getResultMsg();
    }
    /**
     * 成功
     */
    public static ResultEntity success(){
        return success(null);
    }

    public static ResultEntity success(Object data){
        ResultEntity resultEntity=new ResultEntity();
        resultEntity.setCode(ResultEnum.success.getResultCode());
        resultEntity.setMessage(ResultEnum.success.getMessage());
        resultEntity.setData(null);
        return resultEntity;
    }

    public static ResultEntity error(BaseErrorInfoInterface baseErrorInfoInterface){
        ResultEntity resultEntity=new ResultEntity();
        resultEntity.setCode(baseErrorInfoInterface.getResultCode());
        resultEntity.setMessage(baseErrorInfoInterface.getResultMsg());
        resultEntity.setData(null);
        return resultEntity;
    }


    public static ResultEntity error(String message,String code){
        ResultEntity resultEntity=new ResultEntity();
        resultEntity.setCode(code);
        resultEntity.setMessage(message);
        resultEntity.setData(null);
        return resultEntity;
    }

    public static ResultEntity error(String message){
        ResultEntity resultEntity=new ResultEntity();
        resultEntity.setCode("-1");
        resultEntity.setMessage(message);
        resultEntity.setData(null);
        return resultEntity;
    }



    @Override
    public String toString() {
        return "ResultEntity{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
